package com.dragonfly.shutter.services;

import java.util.Date;

import com.dragonfly.shutter.DAOs.BrowseLogDAO;
import com.dragonfly.shutter.DAOs.PictureDAO;
import com.dragonfly.shutter.beans.BrowseLog;

/**
 * 举报图片服务类
 * @author 黄挺
 *
 */
public class InformAgainstPictureService {
	BrowseLogDAO browseLogDAO;
	PictureDAO pictureDAO;
	
	/**
	 * 举报图片服务函数，修改图片Bean审查标记位，然后进行数据库操作
	 * @param picture 图片Bean
	 * @param requestURL 请求URL
	 * @return 修改后的图片Bean
	 */
	public void doService(String pictureID, Integer userID, String requestURL){
		BrowseLog browseLog = null;
		
		if(userID == null)
			browseLog = new BrowseLog(new Date(System.currentTimeMillis()), requestURL);
		else
			browseLog = new BrowseLog(userID, new Date(System.currentTimeMillis()), requestURL);
		
		doDBOperate(pictureID, "reported", browseLog);
	}

	/**
	 * 举报图片数据库操作函数
	 * @param picture 图片Bean
	 * @param requestURL 请求URL
	 */
	public void doDBOperate(String pictureID, String flagCheck, BrowseLog browseLog){
		browseLogDAO.insertBrowseLog(browseLog);
		pictureDAO.updatePictureCheckFlag(pictureID, flagCheck);
	}

	public void setBrowseLogDAO(BrowseLogDAO browseLogDAO) {
		this.browseLogDAO = browseLogDAO;
	}

	public void setPictureDAO(PictureDAO pictureDAO) {
		this.pictureDAO = pictureDAO;
	}
}
